package com.byit.controller;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.plugins.Page;
import com.byit.builder.MapBuilder;
import com.byit.constant.DefaultValue;
import com.byit.domain.SysRole;
import com.byit.enums.PromptInfo;
import com.byit.msg.MessageResult;
import com.byit.service.ISysBehaviorLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wangx
 * @since 2019-01-16
 */
@RestController
@RequestMapping("/api/sys/sysBehaviorLog")
public class SysBehaviorLogController {

    @Autowired
    private ISysBehaviorLogService behaviorLogService;

    @GetMapping("/list")
    public Object selectBehaviorLog(HttpSession session,
                                    @RequestParam(value = "ip", defaultValue = "") String ip,
                                    @RequestParam(value = "page", defaultValue = DefaultValue.PAGE_FIRST) int page,
                                    @RequestParam(value = "limit", defaultValue = DefaultValue.PAGE_SIZE) int limit) {
        Page<SysRole> pageInfo = new Page<>(page, limit);
        Map<String, Object> params = MapBuilder.newMap(1).setParam("ip", ip).ok();
        Page<JSONObject> result = behaviorLogService.selectBehaviorLog(pageInfo, params);
        return MessageResult.warpper(PromptInfo.SYS_SECCUSS, result);
    }
}
